#coding=utf-8

import os
import  configparser
from log import logger

from global_utils.mysql_helper import DBConn

class ParserWsConfig(object):
    def __init__(self, ws_conf):
        config = configparser.ConfigParser()

        config.read(ws_conf, encoding='utf-8')
        try:
            self.host = config['GETCASE']['host'].encode("UTF-8")
            self.port = config['GETCASE']['port'].encode("UTF-8")
            self.project_uri = config['GETCASE']['getproject'].encode("UTF-8")
            self.interface_uri = config['GETCASE']['getinterface'].encode("UTF-8")
            self.case_uri = config['GETCASE']['getcase'].encode("UTF-8")
            
            self.db_name = config['DBCONN']['dbname'].encode("UTF-8")
            self.db_user = config['DBCONN']['user'].encode("UTF-8")
            self.db_passwd = config['DBCONN']['passwd'].encode("UTF-8")
            self.db_host = config['DBCONN']['host'].encode("UTF-8")
            self.db_port = int(config['DBCONN']['port'])
            
            self.db_info={
                 "host":self.db_host,
                 "user":self.db_user,
                 "passwd":self.db_passwd,
                 "db":self.db_name,
                 "port":self.db_port,
                 "charset":"utf8"
        }  
        except Exception as e:
            logger.error(e)
            exit()
            
    @property
    def get_project(self):
        projec="".join(("http://",self.host,":",self.port,self.project_uri))
        return  projec
     
    @property
    def get_interface(self):
        interface="".join(("http://",self.host,":",self.port,self.interface_uri))
        return interface
      
    @property
    def get_case(self):
        case="".join(("http://",self.host,":",self.port,self.case_uri))
        return case
  
    @property
    def get_db_info(self):
        return self.db_info
    
    @property
    def get_db_conn(self):
        return DBConn(self.db_info)
        
    
    
     
config_path=os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir,"config","ws_config.conf"))
WSCONFIG=ParserWsConfig(config_path)
if __name__=="__main__":
    print WSCONFIG.get_db_info

    